/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainForm.java
 *
 * Created on Nov 17, 2011, 11:29:03 PM
 */
package view;

import bll.NguoiDungBLL;
import java.awt.*;
import java.beans.PropertyVetoException;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author HoangNam
 * 
 */
public class MainForm extends MasterForm {

    private ImageIcon bgImage;
    //private JPanel background;
    private JDesktopPane desktopPane;
    public static Goods goodsForm;
//    public static FormTransactionMgmt formTransactionManagement = null;
//    public static BookFrm frmBook = null;
//    public static UserInfo formAccount = null;
//    public static SystemParam sysPar = null;
//    public static borrowBook frmReportBorrow = null;

    /** Creates new form MainForm */
    public MainForm() {
        FormatForm();
        desktopPane = new JDesktopPane() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (bgImage != null) {
                    g.drawImage(bgImage.getImage(), 0, 0, getWidth(), getHeight(), null);
                }
            }
        };
        setContentPane(desktopPane);
        initComponents();
        
        NguoiDungBLL nd = NguoiDungBLL.init();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu6 = new javax.swing.JMenu();
        jMenu7 = new javax.swing.JMenu();
        menu = new javax.swing.JMenuBar();
        mnGoods = new javax.swing.JMenu();
        mnBook = new javax.swing.JMenu();
        mnTransaction = new javax.swing.JMenu();
        mnStatistic = new javax.swing.JMenu();
        mnuReportBook = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        mnuReportEmployee = new javax.swing.JMenuItem();
        mnHelp = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();

        jMenu6.setText("File");
        jMenuBar2.add(jMenu6);

        jMenu7.setText("Edit");
        jMenuBar2.add(jMenu7);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        menu.setBackground(new java.awt.Color(51, 102, 255));

        mnGoods.setBackground(new java.awt.Color(15, 125, 178));
        mnGoods.setForeground(new java.awt.Color(255, 255, 255));
        mnGoods.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/goods.png"))); // NOI18N
        mnGoods.setMnemonic('h');
        mnGoods.setText("Hàng hóa");
        mnGoods.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnGoods.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnGoodsMouseClicked(evt);
            }
        });
        menu.add(mnGoods);

        mnBook.setBackground(new java.awt.Color(15, 125, 178));
        mnBook.setForeground(new java.awt.Color(255, 255, 255));
        mnBook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/book (2).png"))); // NOI18N
        mnBook.setMnemonic('B');
        mnBook.setText("Book");
        mnBook.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnBook.setVerifyInputWhenFocusTarget(false);
        mnBook.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnBookMouseClicked(evt);
            }
        });
        menu.add(mnBook);

        mnTransaction.setBackground(new java.awt.Color(15, 125, 178));
        mnTransaction.setForeground(new java.awt.Color(255, 255, 255));
        mnTransaction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/transaction.png"))); // NOI18N
        mnTransaction.setText("Transaction");
        mnTransaction.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnTransaction.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnTransactionMouseClicked(evt);
            }
        });
        menu.add(mnTransaction);

        mnStatistic.setBackground(new java.awt.Color(15, 125, 178));
        mnStatistic.setForeground(new java.awt.Color(255, 255, 255));
        mnStatistic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/Statistics.png"))); // NOI18N
        mnStatistic.setMnemonic('t');
        mnStatistic.setText("Statistic");
        mnStatistic.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnStatistic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnStatisticActionPerformed(evt);
            }
        });

        mnuReportBook.setBackground(new java.awt.Color(15, 125, 178));
        mnuReportBook.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnuReportBook.setForeground(new java.awt.Color(255, 255, 255));
        mnuReportBook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/mnuBook.png"))); // NOI18N
        mnuReportBook.setText("Book Statistic");
        mnuReportBook.setPreferredSize(new java.awt.Dimension(271, 27));
        mnuReportBook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuReportBookActionPerformed(evt);
            }
        });
        mnStatistic.add(mnuReportBook);

        jMenuItem8.setBackground(new java.awt.Color(15, 125, 178));
        jMenuItem8.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jMenuItem8.setForeground(new java.awt.Color(255, 255, 255));
        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/mnubookborrow.png"))); // NOI18N
        jMenuItem8.setText("Borrowed Book Statistic");
        jMenuItem8.setPreferredSize(new java.awt.Dimension(271, 27));
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        mnStatistic.add(jMenuItem8);

        mnuReportEmployee.setBackground(new java.awt.Color(15, 125, 178));
        mnuReportEmployee.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        mnuReportEmployee.setForeground(new java.awt.Color(255, 255, 255));
        mnuReportEmployee.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/mnuemployee.png"))); // NOI18N
        mnuReportEmployee.setText("Emloyee Statistic");
        mnuReportEmployee.setPreferredSize(new java.awt.Dimension(271, 27));
        mnuReportEmployee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuReportEmployeeActionPerformed1(evt);
            }
        });
        mnStatistic.add(mnuReportEmployee);

        menu.add(mnStatistic);

        mnHelp.setBackground(new java.awt.Color(15, 125, 178));
        mnHelp.setForeground(new java.awt.Color(255, 255, 255));
        mnHelp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/help.png"))); // NOI18N
        mnHelp.setMnemonic('h');
        mnHelp.setText("Help");
        mnHelp.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N

        jMenuItem6.setBackground(new java.awt.Color(15, 125, 178));
        jMenuItem6.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jMenuItem6.setForeground(new java.awt.Color(255, 255, 255));
        jMenuItem6.setText("About");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        mnHelp.add(jMenuItem6);

        jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jMenuItem7.setBackground(new java.awt.Color(15, 125, 178));
        jMenuItem7.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jMenuItem7.setForeground(new java.awt.Color(255, 255, 255));
        jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/help_icon.png"))); // NOI18N
        jMenuItem7.setText("Help");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        mnHelp.add(jMenuItem7);

        menu.add(mnHelp);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 516, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
//        Login login = new Login(this);
//        login.setVisible(true);
//        this.setVisible(false);
    }//GEN-LAST:event_formWindowOpened

    private void jMenu4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu4MouseClicked
        // TODO add your handling code here:
        

    }//GEN-LAST:event_jMenu4MouseClicked

/*
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jMenuItem1ActionPerformed
*/
    private void jMenuItem4ActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed1
        // TODO add your handling code here:
                
    }//GEN-LAST:event_jMenuItem4ActionPerformed1

/*
    private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuReportEmployeeActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_mnuReportEmployeeActionPerformed

     /*
     private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {                                                  
     // TODO add your handling code here:
        
     }                                                 
     */
    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        try {
            String path = new File("").getAbsolutePath() + "\\Help.chm";
            File file = new File(path);

            if (file.exists()) {
                Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + path);
            } else {
                throw new Exception("File \"Help.chm\" not found!");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Notice", JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    /*
     private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {                                                  
     // TODO add your handling code here:
        
     }                                                 
     */
    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        //        AboutUs aFrame = new AboutUs();
        //        desktopPane.add(aFrame);
        //        aFrame.setVisible(true);
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    /*
     private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {                                                  
     // TODO add your handling code here:
        
     }                                                 
     */
    private void mnStatisticActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnStatisticActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mnStatisticActionPerformed

    /*
     private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {                                                  
     // TODO add your handling code here:
        
     }                                                 
     */
    private void mnuReportEmployeeActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuReportEmployeeActionPerformed1
        // TODO add your handling code here:
        //        try {
        //            String reportName = "report/reportEmployee.jasper";
        //            reportEmployee employee = new reportEmployee(reportName);
        //            employee.setBounds(0, 0, desktopPane.getWidth(), desktopPane.getHeight());
        //            employee.setVisible(true);
        //            desktopPane.add(employee);
        //            employee.setSelected(true);
        //        } catch (Exception ex) {
        //            //ex.printStackTrace();
        //            displayFailure("Cannot report! Please try again later!");
        //            System.out.println(ex.getMessage());
        //        }
    }//GEN-LAST:event_mnuReportEmployeeActionPerformed1

    /*
     private void mnuReportEmployeeActionPerformed(java.awt.event.ActionEvent evt) {                                                  
     // TODO add your handling code here:
        
     }                                                 
     */
    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // TODO add your handling code here:
        //        if(frmReportBorrow == null) {
        //            frmReportBorrow = new borrowBook(this.desktopPane);
        //            desktopPane.add(frmReportBorrow);
        //            frmReportBorrow.setVisible(true);
        //        } else {
        //            try {
        //                frmReportBorrow.setSelected(true);
        //            } catch (Exception ex) {
        //                displayFailure("Cannot open window selected! Please try again later!");
        //                ex.printStackTrace();
        //            }
        //        }
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    /*
     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
     // TODO add your handling code here:
        
     }                                          
     */
    private void mnuReportBookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuReportBookActionPerformed
        // TODO add your handling code here:
        //        try {
        //            String reportName = "report/reportBook.jasper";
        //            JOptionPane.showMessageDialog(null, reportName);
        //            reportBook book = new reportBook(reportName);
        //            book.setBounds(0, 0, desktopPane.getWidth(), desktopPane.getHeight());
        //            book.setVisible(true);
        //            desktopPane.add(book);
        //            book.setSelected(true);
        //        } catch (Exception ex) {
        //            //ex.printStackTrace();
        //            displayFailure("Cannot report! Please try again later!");
        //            System.out.println(ex.getMessage());
        //        }
    }//GEN-LAST:event_mnuReportBookActionPerformed

    private void mnTransactionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnTransactionMouseClicked
        //        if (formTransactionManagement == null) {
        //            formTransactionManagement = new FormTransactionMgmt();
        //            desktopPane.add(formTransactionManagement);
        //            //frm.setSize(800,600);
        //            formTransactionManagement.setVisible(true);
        //        } else {
        //            try {
        //                formTransactionManagement.setSelected(true);
        //                //            formEmpManagement.show();
        //                //            formEmpManagement.show();
        //            } catch (PropertyVetoException ex) {
        //                ex.printStackTrace();
        //            }
        //        }
    }//GEN-LAST:event_mnTransactionMouseClicked

    private void mnBookMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnBookMouseClicked
        //        if (frmBook == null) {
        //            frmBook = new BookFrm();
        //            desktopPane.add(frmBook);
        //            //frmBook.setLocation(200, 100);
        //            frmBook.setVisible(true);
        //
        //        } else {
        //            try {
        //                frmBook.setSelected(true);
        //            } catch (Exception ex) {
        //                displayFailure("Cannot open window selected! Please try again later!");
        //                ex.printStackTrace();
        //            }
        //        }
    }//GEN-LAST:event_mnBookMouseClicked

    private void mnGoodsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnGoodsMouseClicked
        if (goodsForm == null) {
            try {
                goodsForm = new Goods();
                desktopPane.add(goodsForm);
                goodsForm.setVisible(true);
                goodsForm.setMaximum(true);
            } catch (PropertyVetoException ex) {
                ex.printStackTrace();
            }
        } else {
            try {
                goodsForm.setSelected(true);
            } catch (PropertyVetoException ex) {
            }
        }
    }//GEN-LAST:event_mnGoodsMouseClicked
    /**
     * @param args the command line arguments
     */
    /* public static void main(String args[]) {
     try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     } catch (Exception ex) {
     ex.printStackTrace();
     }
     MainForm frame = new MainForm();
     frame.setVisible(true);
     //set maximum size
     frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
     frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
     //frame.setIconImage(createImages("src\\image\\book.png").getImage());
     //set icon for title
     frame.setBackground(new ImageIcon("src\\image\\theme.jpg"));
     }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu7;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenu mnBook;
    private javax.swing.JMenu mnGoods;
    private javax.swing.JMenu mnHelp;
    private javax.swing.JMenu mnStatistic;
    private javax.swing.JMenu mnTransaction;
    private javax.swing.JMenuItem mnuReportBook;
    private javax.swing.JMenuItem mnuReportEmployee;
    // End of variables declaration//GEN-END:variables

    public void setBackground(ImageIcon imageIcon) {
        this.bgImage = imageIcon;
    }
}
